package com.zhb.cloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zhb.cloud.model.User;
import com.zhb.cloud.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@RestController
@RequestMapping("/user")
@Api("用户相关api")
public class UserController {

	@Autowired
	private UserService userService;

	/**
	 * @Title: getUser
	 * @author: zhb
	 * @date: 2017年8月29日 上午11:06:47
	 * @Description: paramType：参数放在哪个地方 header-->请求参数的获取：@RequestHeader
	 *               query-->请求参数的获取：@RequestParam
	 *               path（用于restful接口）-->请求参数的获取：@PathVariable body（不常用）
	 *               form（不常用） name：参数名 dataType：参数类型 required：参数是否必须传
	 *               value：参数的意思 defaultValue：参数的默认值
	 * 
	 * @param userName
	 * @return
	 */
	@ApiOperation("获取用户信息")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", name = "userName", dataType = "String", required = true, value = "用户名", defaultValue = "") })
	@ApiResponses({ @ApiResponse(code = 400, message = "请求参数没填好"),
			@ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对") })
	@RequestMapping(value = "/getUser", method = RequestMethod.GET)
	public User getUser(@RequestParam(name = "userName", required = true) String userName) {
		return userService.getUserByUserName(userName);
	}
}